<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银行系统 - 修改密码</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

h2 {
    color: #333;
}

form {
    max-width: 400px;
    margin-top: 20px;
}

.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 5px;
}

input[type="password"] {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

button {
    padding: 10px 15px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

button:hover {
    background-color: #45a049;
}
</style>
</head>
<body>
    <h2>修改密码</h2>
    
    <form id="changePasswordForm">
        <div class="form-group">
            <label for="oldPassword">旧密码：</label>
            <input type="password" id="oldPassword" name="oldPassword" required>
        </div>
        
        <div class="form-group">
            <label for="newPassword">新密码：</label>
            <input type="password" id="newPassword" name="newPassword" required>
        </div>
        
        <div class="form-group">
            <label for="confirmPassword">确认新密码：</label>
            <input type="password" id="confirmPassword" name="confirmPassword" required>
        </div>
        
        <button type="button" onclick="changePassword()">提交</button>
    </form>
    
    <script>
    function changePassword() {
        var oldPassword = document.getElementById("oldPassword").value;
        var newPassword = document.getElementById("newPassword").value;
        var confirmPassword = document.getElementById("confirmPassword").value;
        
        if (newPassword !== confirmPassword) {
            alert("两次输入的新密码不一致！");
            return;
        }
        
        // 使用AJAX提交表单
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "changePassword", true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                alert(xhr.responseText);
                if (xhr.responseText.indexOf("成功") !== -1) {
                    // 密码修改成功，跳转到登录页面
                    window.location.href = "login.jsp";
                }
            }
        };
        xhr.send("oldPassword=" + oldPassword + "&newPassword=" + newPassword);
    }
    </script>
</body>
</html>